//
//  UIImageView+PYMediaInfo.m
//  IHome
//
//  Created by Jim on 2019/4/14.
//  Copyright © 2019 com.zhujizheng. All rights reserved.
//

#import "UIImageView+PYMediaInfo.h"
#import "UIImageView+PYWebImage.h"
#import "PYMediaInfo.h"

@implementation UIImageView (PYMediaInfo)

- (void)py_setMediaInfo:(PYMediaInfo *)mediaInfo
{
    [self py_setMediaInfo:mediaInfo progress:nil completion:nil];
}

- (void)py_setMediaInfo:(PYMediaInfo *)mediaInfo
               progress:(nullable void (^)(double progress))progress
             completion:(void (^)(UIImage * _Nonnull))completion
{
    [self py_setMediaInfo:mediaInfo progress:progress transform:nil completion:completion];
}

- (void)py_setMediaInfo:(PYMediaInfo *)mediaInfo
               progress:(nullable void (^)(double progress))progressHandler
              transform:(YYWebImageTransformBlock)transform
             completion:(nullable void (^)(UIImage * _Nonnull image))completion
{
    if (transform) {
        // 裁剪还带动画的效果不太好
        mediaInfo.options = kNilOptions;
    }
    
    [self py_setImageURLString:mediaInfo.imgUrl
                   placeholder:mediaInfo.placeholderImg
                       options:mediaInfo.options
                      progress:progressHandler
                     transform:transform
                    completion:completion];
}
@end
